USE Liberty
GO
-- ------------------------------------------------------------------------------------------------
-- Unit Assignments Table
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Table dbo.UnitAssignments...'
GO

IF OBJECT_ID('dbo.UnitAssignments', 'U') IS NULL
BEGIN
	CREATE TABLE dbo.UnitAssignments
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,Version			rowversion
	,ServiceMan			bigint						NOT NULL
	,RelatedService		bigint						NOT NULL
	,Unit				varchar(200)				NOT NULL
	,Location			varchar(200)				NOT NULL
	,DateUpdated		datetime					NOT NULL
		CONSTRAINT DFLT_UnitAssignments_DateUpdated DEFAULT GETDATE()
	,DateCreated		datetime					NOT NULL
		CONSTRAINT DFLT_UnitAssignments_DateCreated DEFAULT GETDATE()

	,CONSTRAINT PK_UnitAssignments PRIMARY KEY CLUSTERED( OID ) --ON PRIMARY

	,CONSTRAINT FK_UnitAssignments_ServiceMen FOREIGN KEY (ServiceMan)
		REFERENCES ServiceMen(OID)

	,CONSTRAINT FK_UnitAssignments_ServiceHistory FOREIGN KEY (RelatedService)
		REFERENCES ServiceHistory(OID)
	)

	PRINT 'Table dbo.UnitAssignments has been created successfully.'

END
ELSE 
BEGIN
    PRINT 'Table dbo.UnitAssignments already exists.'
END

GO
